package com.wn.pettyloan.security.emp;

import com.wn.pettyloan.entity.Emp;
import com.wn.pettyloan.vo.PermissionVo;
import lombok.Data;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

/**
 * @program: pettyloan
 * @ClassName LoginEmp
 * @description:
 * @author: 韩旭
 * @create: 2022-12-15 14:55
 **/
@Data
public class LoginEmp implements UserDetails {
    private Emp emp;
    private List<PermissionVo> menuList;
    private String token;
    private List<String> permissions;
    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        ArrayList<SimpleGrantedAuthority> authorities = new ArrayList<>();
        if (permissions != null) {
            for (String permission : permissions) {
                authorities.add(new SimpleGrantedAuthority(permission));
            }
        }
        return authorities;
    }

    @Override
    public String getPassword() {
        return emp.getEmpPassword();
    }

    @Override
    public String getUsername() {
        return emp.getEmpUacc();
    }

    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    @Override
    public boolean isEnabled() {
        return true;
    }

}